package nl.mkmedia.tuio.behaviours {
	import nl.mkmedia.tuio.TUIOPoint;
	import flash.display.DisplayObject;
	import flash.geom.Point;

	/**
	 * @author Mingoes Kukupessy (mingoes at gmail dot com)
	 */
	public class BScale extends BaseBehaviour{
	
		public function BScale(displayObject : DisplayObject)
		{
			super(displayObject);
		}
		
		override public function act(points:Array) : void
		{
			super.act(points);
			if(pointsOn.length == 2) {
				if(pointsOn[0].oldX == 0 || pointsOn[0].oldY == 0 || pointsOn[1].oldX == 0 || pointsOn[1].oldY == 0) return;
				var oldLength:Number = Point.distance(TUIOPoint(pointsOn[0]).oldPoint, TUIOPoint(pointsOn[1]).oldPoint);
				var newLength:Number = Point.distance(pointsOn[0], pointsOn[1]);
				displayObject.scaleX = displayObject.scaleY *= newLength / oldLength;
			}
		}
		
	}
}
